#coding:utf-8
from spider.BaiduSiteSpider import BaiduSiteSpider
from spider.BiyingSiteSpider import BiyingSiteSpider
from spider.middle.BloomFilter import BloomFilter
import time
from spider.conf import conf
import mysql.connector

class run:
    page = 1
    def makeBloomFilter(self,name):
        return BloomFilter(0.1,100000,"bloom_"+name+".txt")
    def __init__(self,name):
        self.conn = mysql.connector.connect(user=conf.USERNAME, password=conf.PASSWORD, database=conf.DATABASE, use_unicode=True)
        self.cursor = self.conn.cursor()
        self.name = name
        self.bloom = self.makeBloomFilter(name)
    def run(self):
        pass
    def getTime(self):
        self.cursor.execute("select T from spider where type=%s and username='admin'",[self.name])
        time = self.cursor.fetchone()
        if time:
            return int(time[0])*60
        return 7200
    def start(self):
        while(True):
            self.run()
            print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
            time.sleep(self.getTime())
if __name__=="__main__":
    a = run("boke")
    print(a.getTime())